package com.reesechou.controller.admin;

import com.reesechou.javabean.Category;
import com.reesechou.javabean.Tag;
import com.reesechou.service.CategoryService;
import com.reesechou.service.TagService;
import org.directwebremoting.util.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * Created by 小星打屁屁 on 2015/4/11.
 * contact me ==>243709758@qq.com
 */
@Controller
@RequestMapping("/jsp/admin/content")
public class TagController {
   private static Logger logger =  Logger.getLogger(TagController.class);

    private  static  String  LIST_PAGE = "tag_list";
    private  static  String  ADD_PAGE = "tag_add";

    @Autowired
    private CategoryService categoryService ;
    @Autowired
    private TagService tagService ;

    @RequestMapping("/tag_list")
    public String getTagList(HttpServletRequest request ,HttpServletResponse response ,Model model){
        logger.info("跳转到标签分类的列表");
        List<Tag> list = tagService.getAllTag();
        model.addAttribute("tagList",list);
        return  LIST_PAGE ;
    }
    @RequestMapping(value = "/tag_add",method = RequestMethod.GET)
    public String toTagAdd(HttpServletRequest request ,HttpServletResponse response ,Model model){
        logger.info("跳转到标签新增页面");
        List<Tag> list = tagService.getAllTag();
        model.addAttribute("tagList",list);
        return ADD_PAGE ;
    }

    @RequestMapping(value = "/tag_add",method = RequestMethod.POST)
    public String doTagAdd(HttpServletRequest request ,HttpServletResponse response ,Tag tag ,Model model){

        initTag(tag);
        if(tagService.insert(tag)==1){
            logger.info("添加标签成功");
        }else{
            logger.error("添加标签失败");
        }
        return "redirect:"+ADD_PAGE ;
    }

    public void initTag(Tag tag){


    }
}
